﻿using System;
using System.Text;

namespace BizElements.Core.ProviderComponents
{
    /// <summary>Renders LIKE predicate as SQL element.</summary>
    sealed class GenericLikeRenderer : ILikePredicateRenderer
    {
        /// <summary>Renders LIKE predicate as SQL element.</summary>
        /// <param name="like">Like predicate.</param>
        /// <param name="dbms">Target DBMS.</param>
        /// <param name="output">StringBuilder to which SQL is appended.</param>
        /// <param name="parameters">SQL parameter collection to which the object's and its children's
        /// parameters are added. After the rendering is done the collection contains all parameters with unique names.</param>
        public void Render(LikePredicate like, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            output.Append("(");
            like.PredicateItems[0].Render(dbms, output, parameters);

            if (like.Negate)
                output.Append(" NOT LIKE ");
            else
                output.Append(" LIKE ");

            like.PredicateItems[1].Render(dbms, output, parameters);
            output.Append(")");    
        }
    }

}